package top.swle.austers.mapper;

import top.swle.austers.bean.Trip;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface TripMapper {
    @Insert("INSERT INTO car_pool(发起者,起始地,目的地,剩余座位,年,月,日,时) VALUES(" +
            "#{initiator},#{starting},#{destination},#{seat_left},#{year},#{month},#{day},#{hour})")
    void issueTrip(Trip trip);

    @Update("UPDATE car_pool SET 剩余座位=剩余座位-1 WHERE ID = #{id}")
    void getInTrip(Trip trip);

    @Select("SELECT id,发起者 as initiator,剩余座位 as seat_left,月 as month,日 as day,时 as hour FROM car_pool WHERE " +
            "起始地=#{starting} and 目的地=#{destination} and 年=#{year} and 月=#{month} and 日=#{day} and 剩余座位 >0")
    List<Trip> queryOtherTrip(Trip trip);
}
